package cn.tedu.smartos.uploadfile.controller;

import cn.tedu.smartos.base.response.JsonResult;
import cn.tedu.smartos.uploadfile.service.UploadService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@Api(tags = "上传图片功能")
@Slf4j
@RestController
@RequestMapping("/api/v1/")
public class UploadController {
    @Autowired private UploadService uploadService;

    //多图上传
//    @PostMapping("/upload")
//    public ResponseEntity<?> uploadImages(@RequestParam("files") MultipartFile[] files) {
//        log.debug("收到文件上传请求: {} 文件数量 {}", files.length+"test");
//        return uploadService.uploadImages(files); // 新增方法处理多个文件
//    }
    @PostMapping("/upload")
    public ResponseEntity<?> uploadImages(
            @RequestParam("files") MultipartFile[] files,
            @RequestParam("type") String type) {
        return uploadService.uploadImages(files, type);
    }

    // 批量删除图片
    @PostMapping("/delete")
    public JsonResult deleteImages(@RequestBody List<String> filePaths) {
        log.debug("收到批量删除图片请求: {}", filePaths);
        uploadService.deleteImages(filePaths);
        return JsonResult.ok();
    }
}
